package com.fsp.controller;

import com.fsp.domain.Test;
import com.fsp.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author fushengping
 * @className TestController
 * @description
 * @date 2021/7/22 22:19
 */

//前后端分离的条件下，只需要返回json字符串即可
@RestController //只返回字符串
//@Controller 前后端不分离这个返回页面
@RequestMapping("/test")
public class TestController {

    @Autowired
    private TestService testService;

    /*优先读取application.properties中的配置项值，若配置项中没有设置，则读取默认值:test*/
    @Value("${test.hello:test}")
    private String testHello;

    //测试
    @RequestMapping("/test1")
    public String test(){
        return "hello" + testHello;//这里返回的是字符串格式
    }
    /*测试Post请求*/
    @PostMapping("/test/post")
    public String post(String name){
        return "hello " + name;
    }

    //查询test信息
    @GetMapping("/list")
    public List<Test> list(){
        return testService.list();
    }
}
